(function($){
    /**
     * 隐藏元素,当鼠标点击其它任意地方时.
     * @method hideOnClickDoc
     */
    $.fn.hideOnClickDoc = function(cb){    
        var $wrapper = $(this);
        $(window).on('click', function(e){
            if(!$.contains($wrapper.get(0), e.target) && $wrapper.get(0) !== e.target ){
                if(cb){
                    if(cb($wrapper) !== false){
                        $wrapper.hide();    
                    }
                } else {
                    $wrapper.hide();
                }
            }            
        });
    };
    /*
     * |-------------|
     * |   1  |   2  |
     * |------|------|
     * |   3  |   4  |
     * |------|------|
     * 获取鼠标位置.
     * e : mousemove event.
     */
    $.fn.mousePosition = function(e){
        var $self = $(this);
        var selfPos = $self.offset();
        var selfSize = {
            width : $self.outerWidth(),
            height : $self.outerHeight()
        };
        var selfCenterPos = {
            left : selfPos.left + selfSize.width / 2,
            top : selfPos.top + selfSize.height / 2  
        };
        var mousePos = {
            left : e.pageX,
            top : e.pageY
        };
        
        if(mousePos.top <= selfCenterPos.top){
            if(mousePos.left <= selfCenterPos.left){
                return 1;
            } else {
                return 2;
            }
        } else {
            if(mousePos.left <= selfCenterPos.left){
                return 3;
            } else {
                return 4;
            }
        }
    };    
    /**
     * 模拟点击超链接.
     */
    $.fn.clickLink = function(){
        if($.browser.msie){ 
            $(this).get(0).click(); 
        } else { 
            var evt = document.createEvent("MouseEvents"); 
            evt.initEvent("click", false, false); 
            $(this).get(0).dispatchEvent(evt);    
        }        
    };
})(jQuery);